LinqConnect Documentation
Devart.Data.Linq Namespace / Table<TEntity> Class / Attach Method / Attach(TEntity,Boolean) Method
The entity to be attached.
True to attach the entity as modified.
Example

Attach(TEntity,Boolean) Method
Attaches an entity to the DataContext in either a modified or unmodified state.
Syntax
'Declaration
 
Public Overloads Sub Attach( _
   ByVal entity As TEntity, _
   ByVal asModified As Boolean _
) 
 

Parameters

entity
The entity to be attached.
asModified
True to attach the entity as modified.
Remarks
If attaching as modified, the entity must either declare a version member or must not participate in update conflict checking. When a new entity is attached, deferred loaders for any child collections (for example, EntitySet collections of entities from associated tables) are initialized. When SubmitChanges is called, members of the child collections are put into an Unmodified state. To update members of a child collection, you must explicitly call Attach and specify that entity.
Example
using (Northwnd db = new Northwnd(@"c:\northwnd.mdf"))
{
   // Get original Customer from deserialization.
var q1 = db.Orders.First();
string serializedQ = SerializeHelper.Serialize(q1);
var q2 = SerializeHelper.Deserialize(serializedQ, q1);

   // Track this object for an update (not insert).
   db.Orders.Attach(q2, false);

   // Replay the changes.
   q2.ShipRegion = "King";
   q2.ShipAddress = "1 Microsoft Way";

   // DataContext knows how to update the order.
   db.SubmitChanges();

}
Using db As New Northwnd("")
    ' Get original Customer from deserialization.
Dim q1 = db.Orders.First()
Dim serializedQ As String = SerializeHelper.Serialize(q1)
Dim q2 = SerializeHelper.Deserialize(serializedQ, q1)

    ' Track this object for an update (not insert).
    db.Orders.Attach(q2, False)

    ' Replay the changes.
q2.ShipRegion = "King"
q2.ShipAddress = "1 Microsoft Way"

    ' DataContext knows how to update the order.
    db.SubmitChanges()
End Using
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also